import React, { Component } from 'react'
import {
	Text, View, TouchableOpacity
} from "react-native";
import { SpaceBetween } from '../../../create/_components/SpaceBetween.js';
import { CURRENCY } from '../../../../../utils/helper';
import MethodUtil from '../../../../../utils/MethodUtil';
import { styles } from '../../_common/style';
import OrderApproveService from '../../_common/service';
import { LightBox } from '../../../../../component/Store';
const scale = GLOBAL.SCALE;
//意向客户
export class PotentialClientSection extends Component {
	constructor(props) {
		super(props);
		this.state = {
			loaded: false
		}

		this._closeLightBox = this._closeLightBox.bind(this);
		this.lightBoxData = {
			onClosePress: this._closeLightBox,
			modalVisible: false,
			title: '',
			rowDataList: [],
		};
	}

	_closeLightBox () {
		this.lightBoxData.modalVisible = false;
		const { lightBoxVisible } = this.state;
		this.setState({
			lightBoxVisible: !lightBoxVisible,
		});
	}

	//展示意向客户
	async	showCustomLightBox (currency, data) {
		this.setState({
			loaded: true
		});

		this.setState({
			loaded: false
		});
		this.lightBoxData.rowDataList = [];
		this.lightBoxData.modalVisible = true;
		this.lightBoxData.title = '意向客户';
		/*先客户 、商品、数量、单价、时间、类型、
		地址、物流费用、财务费用、资源平衡*/
		let { planLogisticsCost, planFinanceCost, planRemark, companyAddressName, planSellQuantity, companyName, planSellBeginDate, planSellEndDate, planSellPrice, planRecvTypeName, goodsName } = data;
		this.lightBoxData.rowDataList.push({ label: '拟销售客户：', val: companyName });
		this.lightBoxData.rowDataList.push({ label: '拟销售商品：', val: goodsName });
		this.lightBoxData.rowDataList.push({ label: '拟销售数量：', val: planSellQuantity + '吨' });
		this.lightBoxData.rowDataList.push({ label: '拟销售单价：', val: CURRENCY.getUnit(currency).label + MethodUtil.toThousands(planSellPrice, 2) + CURRENCY.getUnit(currency).text });
		this.lightBoxData.rowDataList.push({ label: '拟销售时间：', val: planSellBeginDate + '至' + planSellEndDate });
		this.lightBoxData.rowDataList.push({ label: '拟收款类型：', val: planRecvTypeName });
		this.lightBoxData.rowDataList.push({ label: '拟收货地址：', val: companyAddressName });
		if (planLogisticsCost) {
			this.lightBoxData.rowDataList.push({ label: '物流费用：', val: CURRENCY.getUnit(currency).label + MethodUtil.toThousands(planLogisticsCost, 2) + CURRENCY.getUnit(currency).text });
		}
		if (planFinanceCost) {
			this.lightBoxData.rowDataList.push({ label: '财务费用：', val: CURRENCY.getUnit(currency).label + MethodUtil.toThousands(planFinanceCost, 2) + CURRENCY.getUnit(currency).text });
		}
		if (planRemark) {
			this.lightBoxData.rowDataList.push({ label: '资源平衡：', val: planRemark });
		}

		const { lightBoxVisible } = this.state;
		this.setState({
			lightBoxVisible: !lightBoxVisible
		});
	}

	render () {
		const { data, currency } = this.props;
		return (
			<View style={[styles.itemBox, styles.borders]} >
				<Text style={styles.itemTitle}>意向客户</Text>
				{
					data.map((item, index) => {
						return (
							<TouchableOpacity key={index} activeOpacity={0.5} onPress={() => { this.showCustomLightBox(currency, item) }} style={[styles.budget]}>
								<SpaceBetween iconShow={true} fontLeft={{ title: item.goodsName + '意向客户', style: { width: 150 * scale } }} fontRight={{ title: '查看详情' }} iconShow={true} />
							</TouchableOpacity>
						)
					})
				}
				< LightBox {...this.lightBoxData} />
			</View >
		)
	}
}
